Results

Imports

library(stargazer)
Warning: package 'stargazer' was built under R version 4.1.2

Please cite as: 
 Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
 R package version 5.2.3. https://CRAN.R-project.org/package=stargazer 
library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
✔ ggplot2 3.3.5     ✔ purrr   0.3.4
✔ tibble  3.1.5     ✔ dplyr   1.0.7
✔ tidyr   1.1.4     ✔ stringr 1.4.0
✔ readr   2.0.2     ✔ forcats 0.5.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(patchwork)
library(plotly)

Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':

    last_plot
The following object is masked from 'package:stats':

    filter
The following object is masked from 'package:graphics':

    layout
load("data/models.RData")
wahl_lohn <- readRDS("data/wahl_lohn_mod.rds")

Plots

Basic plot with SB

plot_basic <- ggplot(aes(x = lohn_prozent, y = afd_prozent, label=name), data = wahl_lohn) +
  geom_point(shape = 1) +
  geom_smooth(method = "lm", se = T) +
  labs(
    x = "Anteil Mindestlohnbezieher",
    y = "AfD Stimmen in %",
    title = "AfD Stimmen und Mindestlohnbezieher",
    subtitle = "Kreisebene",
    caption = "Daten: WSI, Bundeswahlleiter"
  ) +
  theme_minimal() #+ #scientific theme
  #coord_cartesian(xlim = c(0, 0.5), ylim = c(0, 0.35)) + #start at 0,0
  # for Sonneberg (16072)
  # geom_point(
  #   data = wahl_lohn %>% filter("kreis" == "16072"),
  #   color = "red",
  # ) + 
  # geom_text(
  #   data = wahl_lohn %>% filter("kreis" == "16072"),
  #   label = "SB",
  #   vjust = 1.3,
  #   hjust = 0,
  #   color = "red"
  # )
ggsave("images/plot_basic.png", plot_basic, width = 10, height = 7)
`geom_smooth()` using formula 'y ~ x'
plotly::ggplotly(plot_basic)
`geom_smooth()` using formula 'y ~ x'

Plot with east germany

ggplot(aes(x = lohn_prozent, y = afd_prozent), data = wahl_lohn) +
  geom_point(aes(color = factor(ost))) +
  geom_smooth(method = "lm") +
  labs(
    x = "Anteil Mindestlohnbezieher",
    y = "AfD Stimmen in %",
    title = "AfD Stimmen und Mindestlohnbezieher",
    subtitle = "Kreisebene",
    caption = "Daten: WSI, Bundeswahlleiter"
  ) +
  scale_color_manual(values = c("red", "blue"), name="Osten") + #color of points
  theme_minimal() + #scientific theme
  coord_cartesian(xlim = c(0, 0.5), ylim = c(0, 0.35))  #start at 0,0
`geom_smooth()` using formula 'y ~ x'

Plot with scale for arbeitslosenquote

ggplot(aes(x = lohn_prozent, y = afd_prozent), data = wahl_lohn) +
  geom_point(aes(color = arbeitslosenquote)) +
  geom_smooth(method = "lm") +
  labs(
    x = "Anteil Mindestlohnbezieher",
    y = "AfD Stimmen in %",
    title = "AfD Stimmen und Mindestlohnbezieher",
    subtitle = "Kreisebene",
    caption = "Daten: WSI, Bundeswahlleiter"
  ) +
  scale_color_viridis_c(name = "Arbeitslosenquote", option="magma", direction=-1) + #color of points
  theme_minimal() + #scientific theme
  coord_cartesian(xlim = c(0, 0.5), ylim = c(0, 0.35))  #start at 0,0
`geom_smooth()` using formula 'y ~ x'

Plot for linkspartei

ggplot(aes(x = lohn_prozent, y = linke_prozent), data = wahl_lohn) +
  geom_point() +
  geom_smooth(method = "lm") +
  theme_minimal() #scientific theme
`geom_smooth()` using formula 'y ~ x'
Warning: Removed 1 rows containing non-finite values (stat_smooth).
Warning: Removed 1 rows containing missing values (geom_point).

Maps

Load GEOJSON Data for Kreise

Data Source = Regionalatlas Statistikportal

spdf <- sf::read_sf("data/kreise.geojson")

Merge

geodata <- spdf %>% 
  left_join(wahl_lohn, by = c("schluessel" = "kreis"))

Afd Stimmen

afd_map <- ggplot(geodata) +
  geom_sf(aes(fill = afd_prozent)) +
  scale_fill_viridis_c(name = "AfD in %", option="magma", direction=-1) +
  theme_minimal() +
  labs(
    title = "AfD Vote Share",
    subtitle = "District Level",
    caption = "Data: Bundeswahlleiter"
  )

Mindestlohn

lohn_map <- ggplot(geodata) +
  geom_sf(aes(fill = lohn_prozent)) +
  scale_fill_viridis_c(name = "MW %", option="magma", direction=-1) +
  theme_minimal() +
  labs(
    title = "Minimum Wage Recipients",
    subtitle = "District Level",
    caption = "Data: WSI"
  )

both maps next to each other

maps <- afd_map + lohn_map
ggsave("images/maps.png",plot=maps, width = 10, height = 5)
subplot(ggplotly(afd_map), ggplotly(lohn_map))

Regression Models Table

Summary Statistic of Data

#stargazer(as.data.frame(wahl_lohn), type="text")
stargazer(as.data.frame(wahl_lohn), type="latex", out="images/summary_table.tex")

?(caption)


% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Wed, Feb 07, 2024 - 18:07:07
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lccccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \\ 
\hline \\[-1.8ex] 
afd\_prozent & 400 & 0.113 & 0.058 & 0.029 & 0.321 \\ 
lohn\_prozent & 400 & 0.194 & 0.064 & 0.079 & 0.440 \\ 
linke\_prozent & 399 & 0.045 & 0.029 & 0.015 & 0.155 \\ 
ost & 400 & 0.190 & 0.393 & 0 & 1 \\ 
arbeitslosenquote & 400 & 0.052 & 0.022 & 0.019 & 0.148 \\ 
gdp & 400 & 40,329.500 & 16,743.150 & 17,553 & 158,749 \\ 
age & 400 & 45.277 & 2.008 & 40.700 & 51.000 \\ 
pop & 400 & 536.540 & 708.669 & 35.300 & 4,788.200 \\ 
foreigners & 400 & 0.114 & 0.055 & 0.025 & 0.375 \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 

Compile List of Models to include in Table

models <- list(
  model_basic,
  model_ost,
  model_arbeit,
  model_gdp,
  model_age,
  model_foreign,
  model_pop
)

Create the Stargazer Table

table <- stargazer(models, 
          #type = "text",
          type = "html",
          out="images/table.html", #
          title = "Effect of Minimum Wage Recipients on AfD Vote Share",
          dep.var.labels = "AfD Vote Share",
          covariate.labels = c(
            "Minimum Wage Rate", 
            "East Germany",
            "Unemployment Rate", 
            "Log GDP p. C.", 
            "Avg. Age", 
            "Log Pop. Density", 
            "Foreigners"
            ),
          df = T,
          omit.stat = c("rsq", "f")
          )

?(caption)

Effect of Minimum Wage Recipients on AfD Vote Share
Dependent variable:
AfD Vote Share
(1)
(2)
(3)
(4)
(5)
(6)
(7)
Minimum Wage Rate
0.714***
0.291***
0.308***
0.301***
0.227***
0.222***
0.202***
(0.028)
(0.039)
(0.039)
(0.044)
(0.044)
(0.043)
(0.043)
East Germany
0.086***
0.088***
0.088***
0.081***
0.088***
0.091***
(0.006)
(0.006)
(0.006)
(0.006)
(0.006)
(0.006)
Unemployment Rate
-0.279***
-0.275***
-0.244***
-0.383***
-0.222**
(0.071)
(0.072)
(0.070)
(0.078)
(0.092)
Log GDP p. C.
-0.002
0.011*
0.002
0.006
(0.005)
(0.006)
(0.006)
(0.006)
Avg. Age
0.006***
0.008***
0.008***
(0.001)
(0.001)
(0.001)
Log Pop. Density
0.175***
0.243***
(0.046)
(0.050)
Foreigners
-0.008***
(0.002)
Constant
-0.026***
0.040***
0.051***
0.071
-0.332***
-0.351***
-0.315***
(0.006)
(0.007)
(0.007)
(0.060)
(0.091)
(0.090)
(0.090)
Observations
400
400
400
400
400
400
400
Adjusted R2
0.612
0.732
0.742
0.741
0.760
0.768
0.773
Residual Std. Error
0.036 (df = 398)
0.030 (df = 397)
0.030 (df = 396)
0.030 (df = 395)
0.029 (df = 394)
0.028 (df = 393)
0.028 (df = 392)
Note:
p<0.1; p<0.05; p<0.01

Rewrite this code with table package gt